package com.qk.management.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qk.common.PageResult;
import com.qk.dpmain.customer.CustomerDo;
import com.qk.dto.Customer.CustomerDto;
import com.qk.dto.Customer.CustomerListDto;
import com.qk.entity.Customer;
import com.qk.management.mapper.CustomerMapper;
import com.qk.management.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @文件名: CustomerServiceImpl
 * @作者: DX
 * @创建日期: 2025/10/16
 * @描述:
 */
@Slf4j
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public void addCustomer(CustomerDto dto) {

        Customer customer = BeanUtil.copyProperties(dto, Customer.class);

        customer.setCreateTime(LocalDateTime.now());
        customer.setUpdateTime(LocalDateTime.now());

        this.customerMapper.insert(customer);
    }

    @Override
    public PageResult<CustomerDo> customerList(CustomerListDto dto) {
        Page<Customer> page = new Page<>(dto.getPage(), dto.getPageSize());
        Page<CustomerDo> customerDoPage = this. baseMapper.customerList(page, dto);
        return PageResult.<CustomerDo>builder()
                .total(Long.valueOf(customerDoPage.getTotal()).intValue())
                .rows(customerDoPage.getRecords())
                .build();
    }
}
